package com.baomidou.kaptcha;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;

import java.util.concurrent.TimeUnit;

/**
 * @author fuwei
 * @since 2019-05-31
 */
public class RedisCacheImpl implements Cache {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public String get(String key) {
        ValueOperations<String, String> valueOps = stringRedisTemplate.opsForValue();
        return valueOps.get(key);
    }

    @Override
    public boolean set(String key, String code, int expires) {
        ValueOperations<String, String> valueOps = stringRedisTemplate.opsForValue();
        valueOps.set(key, code, expires, TimeUnit.SECONDS);
        return true;
    }

    @Override
    public boolean delete(String key) {
        stringRedisTemplate.delete(key);
        return true;
    }



}
